﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Job.Web.Framework;
using Job.Logic.BaseContent;
using Job.Web.userControls.Admin;
using Job.Entity;

namespace Job.Web.userControls.Public
{
    public partial class ContentDetail : BaseCtrl
    {
        int contentId = myR["contentid"].IntValue;
        int subjectid = myR["subjectid"].IntValue;

        BaseContentLogic logic = new BaseContentLogic();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.LoadData();
            }
        }

        private void LoadData()
        {
            
            JobBaseContent content = logic.GetContentByContentId(contentId);
            if (content == null)
            {
                content = logic.GetContentBySubjectId(subjectid);
                if (content == null)
                {
                    tdTitle.InnerText = "页面正在建设中!";
                    return;
                }
            }
            //将点击次数＋1
            if (content.Count.HasValue)
                content.Count += 1;
            else
                content.Count = 1;

            logic.Update(content);

            tdTitle.InnerText = content.Title;
            if (content.Resource != null && content.Resource.Trim().Length > 0)
                tdResource.InnerText = "文章来源：" + content.Resource.Trim();

            tdInfo.InnerText = content.LastUpdateTime.Value.ToString("yyyy年MM月dd日") + ", 点击数 " + content.Count; 
            String con = string.Empty;
            if (content.Content != null)
                con = Server.HtmlDecode(Functions.ByteArrayToString(content.Content));
            tdContent.Controls.Add(new LiteralControl(con));

            if (contentId < 1000)
            {
                tdInfo.Style.Add("display","none");
            }
        }

    }
}